package com.tarena.lbs.business.servcie.impl;

import com.tarena.lbs.business.dao.repository.BusinessCategoryRepository;
import com.tarena.lbs.business.pojo.po.BusinessCategoryPO;
import com.tarena.lbs.business.pojo.vo.BusinessCategoryVO;
import com.tarena.lbs.business.servcie.BusinessCategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class BusinessCategoryServiceImpl implements BusinessCategoryService {
    @Autowired
    private BusinessCategoryRepository businessCategoryRepository;

    @Override
    public List<BusinessCategoryVO> allCategories() {
       List<BusinessCategoryPO> list = businessCategoryRepository.selectAllCategoires();
        List<BusinessCategoryVO> businessCategoryVOS = new ArrayList<>();
       //把PO  转换成VO
        businessCategoryVOS=list.stream().map(po -> {
            BusinessCategoryVO businessCategoryVO = new BusinessCategoryVO();
            BeanUtils.copyProperties(po,businessCategoryVO);
            return businessCategoryVO;
        }).collect(Collectors.toList());
        return businessCategoryVOS;
    }
}

